home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_11_06 / 1106084a < prev    next >
Text File  |  1993-04-06  |  1KB  |  52 lines

  1.      /*******************************************
  2.      *
  3.      *   erode_image_array(..
  4.      *
  5.      *   This function erodes pixels.  If a pixel
  6.      *   equals value and has more than threshold
  7.      *   neighbors equal to 0, then set that
  8.      *   pixel in the output to 0.
  9.      *
  10.      *******************************************/
  11.  
  12. erode_image_array(the_image, out_image,
  13.                   value, threshold)
  14.    short  the_image[ROWS][COLS],
  15.           out_image[ROWS][COLS],
  16.           threshold,
  17.           value;
  18. {
  19.    int    a, b, count, i, j, k,
  20.           length, width;
  21.  
  22.       /***************************
  23.       *
  24.       *   Loop over image array
  25.       *
  26.       ****************************/
  27.  
  28.    for(i=0; i<ROWS; i++)
  29.       for(j=0; j<COLS; j++)
  30.          out_image[i][j] = the_image[i][j];
  31.  
  32.    printf("\n");
  33.  
  34.    for(i=1; i<ROWS-1; i++){
  35.       if( (i%10) == 0) printf("%3d", i);
  36.       for(j=1; j<COLS-1; j++){
  37.          if(the_image[i][j] == value){
  38.             count = 0;
  39.             for(a=-1; a<=1; a++){
  40.                 for(b=-1; b<=1; b++){
  41.                       if(the_image[i+a][j+b] == 0)
  42.                          count++;
  43.                 }  /*  ends loop over b */
  44.             }  /* ends loop over a */
  45.             if(count > threshold) out_image[i][j] = 0;
  46.          }  /* ends if the_image == value */
  47.       }  /* ends loop over j */
  48.    }  /* ends loop over i */
  49.  
  50. }  /* ends erode_image_array */
  51.  
  52.